package com.kstech.mp3604.ui

import android.view.View
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 * author: blankii
 * created on: 2025/5/9 11:10
 * description:
 */
object UiManager {
    /**
     * 使一个view闪烁
     * view:需要闪烁的view对象
     * looper: true=一直闪烁
     */
    fun updateViewShan(view: View, looper: Boolean = false, maxCount: Int = 4): Job {
        var count = 0//闪烁次数
        return CoroutineScope(Dispatchers.IO).launch {
            while (looper || count < maxCount) {
                withContext(Dispatchers.Main) {
                    view.visibility = View.VISIBLE
                }
                delay(400)
                withContext(Dispatchers.Main) {
                    view.visibility = View.INVISIBLE
                }
                delay(400)
                count++
            }
            withContext(Dispatchers.Main) {
                view.visibility = View.VISIBLE
            }
        }
    }
}